package com.bestcem.xm.ticket.controller.vo.ticket.config;

import com.bestcem.xm.ticket.entity.mongo.Ticket;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import javax.annotation.Nullable;
import java.util.Objects;

/**
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/8 17:34
 */
@Data
public class TemplateDetailFieldVO {

    /**
     * content
     */
    @JsonProperty(value = "content")
    private String content;

    /**
     * sourceId
     */
    @JsonProperty(value = "sourceId")
    private String sourceId;

    /**
     * originText
     */
    @JsonProperty(value = "originText")
    private String originText;

    @JsonProperty(value = "value")
    private SurveyAnswer value;

    @Data
    public static class SurveyAnswer {

        @JsonProperty(value = "answer")
        private Object answer;

        @Nullable
        public static SurveyAnswer getInstance(Ticket.TemplateDetailField.SurveyAnswer entity) {
            if (Objects.isNull(entity)) {
                return null;
            }
            SurveyAnswer data = new SurveyAnswer();
            data.setAnswer(entity.getAnswer());
            return data;
        }
    }

    @Nullable
    public static TemplateDetailFieldVO getInstance(Ticket.TemplateDetailField entity) {
        if (Objects.isNull(entity)) {
            return null;
        }
        TemplateDetailFieldVO data = new TemplateDetailFieldVO();
        
        data.setContent(entity.getContent());
        data.setSourceId(entity.getSourceId());
        data.setOriginText(entity.getOriginText());
        data.setValue(SurveyAnswer.getInstance(entity.getValue()));

        return data;
    }
}
